<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:jsf="http://xmlns.jcp.org/jsf"
                xmlns:f="http://xmlns.jcp.org/jsf/core"
                xmlns:h="http://xmlns.jcp.org/jsf/html"
                xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
                xmlns:p="http://primefaces.org/ui">

    <div>
        <p:panel header="Socios de Presente año" style="border:none;">

            <h:form>
                <h:panelGrid columns="3">
                    <h:panelGrid>
                        <div class="dynaFormLabel">  
                            <p:outputLabel value="Año de socios"/>  
                        </div>
                        <p:selectOneMenu value="#{businessAssociateBean.yearBusinessSearch}">
                            <f:selectItem itemLabel="Selecione Año" noSelectionOption="true" />
                            <f:selectItems value="#{businessAssociateBean.listApertureAssociate}"
                                           var="aper" itemLabel="#{aper.year}" itemValue="#{aper.year}" />
                            <p:ajax event="change" update=":formAssDownId:tableAssId"
                                    listener="#{businessAssociateBean.searchAssociateForYearFilter()}" />
                        </p:selectOneMenu>
                    </h:panelGrid>
                    <h:panelGrid>
                        <div class="dynaFormLabel">  
                            <p:outputLabel value="Busqueda"/>  
                        </div>
                        <p:selectOneMenu value="#{businessAssociateBean.filterCard}">
                            <f:selectItem itemLabel="MOSTRAR TODOS" itemValue="1" />
                            <f:selectItem itemLabel="MOSTRAR SOLO LOS QUE NO RECOGEN CARNET" itemValue="2" />
                            <f:selectItem itemLabel="MOSTRAR SOLO CARNET'S EN USO" itemValue="3" />
                            <f:selectItem itemLabel="MOSTRAR SOLO CARNET'S PERDIDOS" itemValue="4" />
                            <f:selectItem itemLabel="MOSTRAR SOCIOS NUEVOS" itemValue="5" />
                            <f:selectItem itemLabel="MOSTRAR SOCIOS QUE RENOVARON" itemValue="6" />
                            <p:ajax event="change" update=":formAssDownId:tableAssId"
                                    listener="#{businessAssociateBean.searchAssociateForYearFilter()}"/>
                        </p:selectOneMenu>
                    </h:panelGrid>
                    <h:panelGrid>
                        <h:commandLink >  
                            <p:graphicImage value="/resources/images/excel.png" width="25" height="25"/>  
                            EXPORTAR
                            <p:dataExporter type="xls" target=":formAssDownId:tableAssId" 
                                            fileName="socios" 
                                            postProcessor="#{businessAssociateBean.postProcessXLS}"/>  
                        </h:commandLink>
                    </h:panelGrid>
                    <h:panelGrid style="color:blue;">
                        Navegar
                        <p:commandButton value="Ir al Reporte &gt;" style="color:blue;"
                                         update=":panelPrincipalId" ajax="false"
                                         action="#{reportBean.initReport()}">
                            <f:setPropertyActionListener value="./pages/content/report/report_total_carnet_emited.xhtml"
                                                         target="#{navigationBean.navigationContent}"/>

                        </p:commandButton>
                    </h:panelGrid>
                </h:panelGrid>
            </h:form>
            <p:separator />
            <h:form id="formAssDownId" >

                <p:dataTable value="#{businessAssociateBean.listTableBA}"
                             var="busas" id="tableAssId" widgetVar="carsTable" 
                             paginator="true" rows="15" filterDelay="600"
                             filteredValue="#{businessAssociateBean.listTableBAFilter}"
                             currentPageReportTemplate="{startRecord}-{endRecord} :TOTAL: {totalRecords}"
                             paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
                             emptyMessage="No exiten socios de este año.">
                    <p:column width="5">
                        <p:menuButton styleClass="menubutton-for-table">  
                            <p:menuitem value="Editar datos" icon="ui-icon-pencil" 
                                        action="#{businessAssociateBean.editPerson(busas.id)}"
                                        update=":panelPrincipalId,:formClose">  
                                <f:setPropertyActionListener value="./pages/content/business_associate/new_associate.xhtml" 
                                                             target="#{navigationBean.navigationContent}"/>
                            </p:menuitem>
                            <p:menuitem value="Perdio Carnet" icon="ui-icon-refresh" 
                                        update=":dialogChangeCardId"
                                        action="#{historyAssociateBean.initValuesLostCard(busas.id)}">
                            </p:menuitem>
                            <p:menuitem value="Eliminar Socio" icon="ui-icon-close" 
                                        update=":removeASSID" oncomplete="removeAssociate.show();"
                                        action="#{businessAssociateBean.prepareRemoveBussinessAssociate(busas.id)}">
                            </p:menuitem>
                            <p:menuitem value="Cambiar Foto" icon="ui-icon-image"
                                        action="#{businessAssociateBean.changeStatePhotoCheck(busas.id)}">
                            </p:menuitem>
                        </p:menuButton>
                    </p:column>
                    <p:column headerText="Dni" filterBy="dni" filterStyle="width: 45px;">
                        #{busas.dni}
                    </p:column>
                    <p:column headerText="Codigo" filterBy="codeCard" filterStyle="width: 45px;"
                              sortBy="codeCard">
                        #{busas.codeCard}
                    </p:column>
                    <p:column headerText="Apell. y Nombre" 
                              filterBy="completeName" sortBy="fatherName">
                        #{busas.completeName}
                    </p:column>
                    <p:column headerText="Correo" >
                        #{busas.email}
                    </p:column>
                    <p:column headerText="Cod.Curso"
                              filterBy="codeCourse" filterStyle="width: 60px;">
                        #{busas.codeCourse}
                    </p:column>
                    <p:column headerText="Celular">
                        #{busas.phone}
                    </p:column>
                    <p:column headerText="Foto" sortBy="photoCheck">
                        <h:panelGroup id="col8">
                            <p:graphicImage value="/resources/images/check-16x16.gif" rendered="#{busas.photoCheck}"/>
                            <p:graphicImage value="/resources/images/ecn-error-16x16.gif" rendered="#{!busas.photoCheck}"/>
                        </h:panelGroup>
                    </p:column>
                </p:dataTable>
            </h:form>

        </p:panel>
    </div>


    <p:dialog modal="true" appendTo="@(body)" header="Confirmar"
              widgetVar="removeAssociate" id="removeASSID" width="50%">
        <h:form>
            <div align="center">
                Esta seguro de que desea remover de los socios 
                a este usuario?
            </div>
            <div class="dynaFormLabel">  
                <p:outputLabel value="Código de socio"/>  
            </div>
            <h:outputText value="#{businessAssociateBean.removeBusinessAssociate.code}"/>
            <div class="dynaFormLabel">  
                <p:outputLabel value="Nombre"/>  
            </div>
            <h:outputText value="#{businessAssociateBean.removeBusinessAssociate.idPerson.name}"/>
            <div class="dynaFormLabel">  
                <p:outputLabel value="Paterno"/>  
            </div>
            <h:outputText value="#{businessAssociateBean.removeBusinessAssociate.idPerson.fatherName}"/>
            <div class="dynaFormLabel">  
                <p:outputLabel value="Paterno"/>  
            </div>
            <h:outputText value="#{businessAssociateBean.removeBusinessAssociate.idPerson.motherName}"/>
            <p class="separator"/>
            <p class="separator"/>
            <div align="center">

                <p:commandButton value="Confirmar" 
                                 action="#{businessAssociateBean.removeAssociate()}"
                                 update=":formAssDownId:tableAssId"
                                 onclick="removeAssociate.hide();"/>

            </div>
        </h:form>
    </p:dialog>

    <p:dialog modal="true" appendTo="@(body)" id="dialogChangeCardId" 
              widgetVar="dialogChangeCard" header="Cambio de Carnet" width="400">
        <div align="center" style="width: 100%;" class="text">
            El cambio de este carnet a otro, tiene un costo de 
            10 nuevos soles, si Ud. está seguro de seguir adelante, 
            lea los datos para verificar y luego confirme.
        </div> 
        <p class="separator" />
        <h:form id="formChangeCard">
            <h:panelGrid columns="2">
                <h:panelGrid>
                    <div class="dynaFormLabel">  
                        <p:outputLabel value="Código de carnet Actual."/>  
                    </div>
                    <h:outputText value="#{historyAssociateBean.businessAssociate.codeCard}" 
                                  style="font-weight: bold;"/>
                </h:panelGrid>
                <h:panelGrid>
                    <div class="dynaFormLabel">  
                        <p:outputLabel value="Nombres completos"/>  
                    </div>
                    <h:outputText value="#{historyAssociateBean.businessAssociate.idPerson.completeName}" 
                                  style="font-weight: bold;"/>

                </h:panelGrid>
            </h:panelGrid>
            <p:separator />
            <div align="center">
                <div class="dynaFormLabel">  
                    <p:outputLabel value="Código Nuevo" for="codeNew"/>  
                </div>
                <p:inputText id="codeNew" required="true" label="Código Nuevo"
                             maxlength="4" value="#{historyAssociateBean.newCodeCard}"
                             style="font-weight: bold;" placeholder="0001">
                </p:inputText>

                <p class="separator" />
                <p:commandButton value="Confirmar" style="font-weight: bold;" process="@this,codeNew"
                                 update="@form,:formAssDownId:tableAssId" validateClient="true" ajax="false"
                                 onclick="dialogChangeCard.show();"
                                 action="#{historyAssociateBean.saveAndChangeCodeCard()}"/>
            </div>

        </h:form>
    </p:dialog>

</ui:composition>